package com.kfm.mapper;

import com.kfm.model.SysUser;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface ISysUserMapper {

    @Select("select * from sys_user where id = #{id}")
    @Results(id = "sysUserResult", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password")
    })
    SysUser selectById(String id);


    @Select("select su.id uid, su.username, su.password,  a.id, a.money, a.user_id  from sys_user su left join account a on a.user_id = su.id where su.id = #{id}")
    @Results(id = "sysUserWithAccounts", value = {
            @Result(id = true, column = "uid", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(property = "accounts", many = @Many( resultMap = "com.kfm.mapper.IAccountMapper.myResult"))
    })
    SysUser selectByIdWithAccounts(String id);

    @Select("select * from sys_user where id = #{id}")
    @Results(id = "sysUserWithAccounts2", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(property = "accounts", column = "id", many = @Many( select = "com.kfm.mapper.IAccountMapper.selectByUserId"))
    })
    SysUser selectByIdWithAccounts2(String id);
}
